<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>充值/提现</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
     <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
          <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
          <link rel="stylesheet" href="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"
        type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.js"
        type="text/javascript"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/global.js"></script>
</head
<style></style>
<body>
<div class="col-sm-12">
    <form class="form-horizontal m-t" id="form" method="post"
          action="${pageContext.request.contextPath}/admin/redPacket_recharge.action">
        <div class="form-group">
            <label class="col-sm-3  control-label"><i class="require">*</i>红包名称:</label>
            <div class="col-sm-8">
                <select name="type" id="type" class="select2" onchange="changeName()">
                	<option value="1">充值</option>
                    <option value="2">提现</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><i class="require">*</i>选择选择公司:</label>
            <div class="col-sm-8">
                <select id="agtCode" name="agtCode" onchange="changeAgtcode()">
                </select>
            </div>
        </div>
        <div class="form-group" style="margin-left: 200px;font-size: 17px;">
            <span id="agtMoney"></span>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label" id="label1"><i class="require">*</i>充值金额:</label>
            <div class="col-sm-8">
                <input class="form-control" name="changeAmount" size="30" value="0.00" onfocus="if(value=='0.00'){value=''}" onkeyup="clearNoNum(this)" onblur="lost(this)"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label" id="label1">备注:</label>
            <div class="col-sm-8">
                <input class="form-control" name="comm" size="30" />
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
$(function () {
	 $(".select2").select2({
         minimumResultsForSearch: -1,
         width:'100%'
     });
	 addAgtCode(1);
});
function addAgtCode(type){
	$.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
    	$("#agtCode").empty();
        $("#agtCode").append("<option value=''>请选择公司</option>");
        for (var i = 0; i < data.length; i++) {
            $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
        }
        $("#agtCode").select2({
            "placeholder": "请选择公司",
            "width": "100%"
        })
    }, "json");
}
function changeAgtcode()
{
  	var agtCode = $("#agtCode").val();
  	$.post("${pageContext.request.contextPath}/admin/redPacket_getAmount.action", {
   		'agtCode': agtCode
    }, function (data) {
		$("#agtMoney").html("本公司账户余额为："+data.amount+" 元");
    }, "json");
}
function changeName(){
	var type = $("#type").val();
	if(type == '1'){
		$("#label1").html("充值金额");
	}else{
		$("#label1").html("提现金额");
	}
}
function clearNoNum(obj)
{
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d.]/g,"");
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g,"");
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g,".");
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
function lost(obj)
{
	var f = obj.value;  
    if (isNaN(f)) {    
        return false;    
    }    
    obj.value=getNum(f); 
}
function getNum(f){
	    
	    var f = Math.round(f*100)/100;    
	    var s = f.toString();    
	    var rs = s.indexOf('.');    
	    if (rs < 0) {    
	        rs = s.length;    
	        s += '.';    
	    }    
	    while (s.length <= rs + 2) {    
	        s += '0';    
	    }    
	    return s;
}
</script>
</body>
</html>
